package logic

import (
	"context"
	"github.com/pkg/errors"
	"mall/common/xerr"

	"mall/app/product/cmd/rpc/internal/svc"
	"mall/app/product/cmd/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteCategoryBatchLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteCategoryBatchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCategoryBatchLogic {
	return &DeleteCategoryBatchLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// DeleteCategoryBatch 根据分类id列表 批量删除分类
func (l *DeleteCategoryBatchLogic) DeleteCategoryBatch(in *pb.DeleteCategoryBatchReq) (*pb.EmptyResp, error) {
	list := in.CatIdList
	err := l.svcCtx.CategoryModel.DeleteBatch(l.ctx, list)
	if err != nil {
		return nil, errors.Wrapf(xerr.NewErrorWithCode(xerr.DbError), "err: %v", err)
	}
	return &pb.EmptyResp{}, nil
}
